<%@ page  contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="p" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<head>
<meta charset="UTF-8">
<title>角色管理</title>
<%@ include file="/common/taglibs.jsp"%>
</head>
<body>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#typedg").datagrid({
				onSelect: function (index,rows){//行     点击事件
					//点击类型请客子项查询条件
					//$('#wfdsItem').searchbox('setValue', '');
					//SearchItem();
					$('#ptypeCode').val(rows.typeCode);
					$('#ptypename').val(rows.typeName);
	            	$("#dg").datagrid({url:'${ctx}/BscDicCode/pfindItems?typeCode='+rows.typeCode});
	            },
				onUnselect: function (rowIndex, rowData) {
	            	
	            }
	        });

		
		});

	</script>
	<!-- 菜单树型列表 -->
	<div id="mainLayout" class="easyui-layout" data-options="fit:true">
		<!-- 菜单设置 -->
		<div title="字典类型列表" iconCls='${icon}' data-options="region:'west',split:true" style="width:50%;">
	 		<div id="tb" style="padding: 10px;">
	 			<form id="sform" method="post">
					<input name="wfds" id="wfds" class="easyui-searchbox"
						data-options="prompt:'请输入名称、类型编码....',searcher:doSearch"
							style="width: 300px"></input>
					<div style="float: right">		
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add"
						 plain="true" onclick="showWin('win','${ctx}/BscDicCode/inputType');">新增</a> 
					
						 <a href="#" class="easyui-linkbutton" iconCls="icon-edit"
							plain="true" onclick="editData('typedg','win','${ctx}/BscDicCode/inputType');">修改</a>
						<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
							plain="true" onclick="deleteData('typedg','${ctx}/BscDicCode/deleteTypeCascade')">删除</a>
									
						</div>
				</form>
			</div>
			
			<table class="easyui-datagrid" id="typedg" style="width: 100%; height: 100%; padding: 0px;"
				data-options="
		        border:false,
                rownumbers:true,
                singleSelect:true,
                autoRowHeight:false,
                pagination:true,
                toolbar:'#tb',
                url:'${ctx}/BscDicCode/getAllTypes',
                pageSize:20">
				<thead>
					<tr>		
						<th data-options="field:'ck',checkbox:true"></th>
						<th field="typeId" hidden=true>typeId</th>
						<th field="typeName" width="25%">名称</th>
						<th field="typeCode" width="25%">类型编码</th>
						<th field="typeCreater" width=15% >创建者</th>
						<th field="typeCreateTime" width=15% >创建时间</th>
						<th field="typeMemo" width=40% >备注</th>
					</tr>
				</thead>
			</table>
		</div>
		
		<div title="字典子项列表"  data-options="region:'center',split:true" style="width: 50%; ">
			<div id="tb2" style="padding: 10px;">
	 			<form id="ssforms" method="post">
				 <input type="hidden" id="ptypeCode" name="ptypeCode"/>
					<input type="hidden" id="ptypename" name="ptypename"/>
					<input name="wfdsItem" id="wfdsItem" class="easyui-searchbox"
						data-options="prompt:'请输入名称、描述....',searcher:SearchItem"
							style="width: 300px"></input>
					<div style="float: right">
						
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add"
						 plain="true" onclick="showItemWin('win','${ctx}/BscDicCode/inputItem');">新增</a> 
					
						 <a href="#" class="easyui-linkbutton" iconCls="icon-edit"
							plain="true" onclick="editData('dg','win','${ctx}/BscDicCode/inputItem');">修改</a>
						<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
							plain="true" onclick="deleteData('dg','${ctx}/BscDicCode/deleteItemsCascade')">删除</a>
							
							
						<a href="#" class="easyui-linkbutton" iconCls="icon-lock"
							plain="true" onclick="changeItem('dg','${ctx}/BscDicCode/enableItem')">启用</a>
							<a href="#" class="easyui-linkbutton" iconCls="icon-lock"
							plain="true" onclick="changeItem('dg','${ctx}/BscDicCode/disableItem')">禁用</a>
								
							
					</div>
				</form>
			</div>
		<table class="easyui-datagrid" id="dg" style="width: 100%; height: 100%; padding: 0px;"
				data-options="
		        border:false,
                rownumbers:true,
                singleSelect:false,
                autoRowHeight:false,
                pagination:true,
                toolbar:'#tb2',
                url:'',
                pageSize:20">
				<thead>
					<tr>		
						<th data-options="field:'ck',checkbox:true"></th>
						<th field="itemId" hidden=true>itemId</th>
						<th field="itemCode"  width="15%">子项编号</th>
						<th field="itemName" width="15%">名称</th>
						<th field="typeCode" width="15%">类型编码</th>
						<th field="itemCreater" width=15% >创建者</th>
						<th field="itemCreateTime" width=15% >创建时间</th>
						<th field="itemIsActive" formatter=formatState width=15% >状态</th>
						<th field="itemMemo" width=42% >备注</th>
					</tr>
				</thead>
			</table>	 	
		</div>
	</div>
	<div id="win" class="easyui-window" title="数据字典管理"
		data-options="iconCls:'${icon}',collapsible:false,minimizable:false,maximizable:false,modal:true,closed:true"
		style="width: 27%; height: 53%; padding: 10px; background-color: #FFFFFF;">
	</div>
	 <div id="winselect" class="easyui-window" title=""
        data-options="iconCls:'icon-add',collapsible:false,minimizable:false,maximizable:false,modal:true,closed:true"
        style="width: 800px; height: 400px; padding: 0px;"></div>
        
	<script>
		function doSearch() {
			$('#typedg').datagrid('options').pageNumber=1;//设置页码初始值为1
			$('#typedg').datagrid({
				queryParams : $('#sform').serializeObject()
			});
		}

        //删除
        function deleteData(gid, url) {
     		var row = $('#' + gid).datagrid('getSelected');
     		var typeid;
     		if(gid=="dg")
     		{
     			typeid=row.itemId;
     		}else
     		{
     			typeid=row.typeId;
     		}
     		if (row != null) {
     			$.messager.confirm('确认', "确认删除吗？", function(r) {
     				if (r) {
     					$.ajax({
     						type : 'post',
     						url : url,
     						data : {
     							'typeId' : typeid
     						},
     						dataType:'json',
     						success : function(data) {
     							if (data) {
     								if (data.success==true) {
     									showMsg('提示', data.message);
     									if (gid && gid != '') {
     										$('#' + gid).datagrid({});
     									}
     								} else {
     									showMsg('提示', data.message);
     								}
     							} else {
     								showMsg('提示', '删除失败！');
     							}
     						},
     						error:function(){
     							alert("业务操作出现错误");
     						}
     					})
     				}
     			})
     		} else {
     			$.messager.alert('警告', '请选择要删除的记录！');
     		}
     	}
        
        
        
        //禁用，启用操作
        function changeItem(gid, url) {
     		var row = $('#' + gid).datagrid('getSelected');
     		if (row != null) {
     		
     					$.ajax({
     						type : 'post',
     						url : url,
     						data : {
     							'itemId' : row.itemId
     						},
     						dataType:'json',
     						success : function(data) {
     							if (data) {
     								if (data.success==true) {
     									showMsg('提示', data.message);
     									if (gid && gid != '') {
     										$('#' + gid).datagrid({});
     									}
     								} else {
     									showMsg('提示', data.message);
     								}
     							} else {
     								showMsg('提示', '操作失败！');
     							}
     						},
     						error:function(){
     							alert("业务操作出现错误");
     						}
     					})
     		} else {
     			$.messager.alert('警告', '请选择要操作的记录！');
     		}
     	}
        
        
        
        
        
        //修改
        function editData(gid, wid, url) {
       		var row = $('#' + gid).datagrid('getSelected');
       		if (row != null) {
       			$('#' + wid).window('open');
       			if(gid=="dg")
       			{
       				var ptypename=$("#ptypename").val(); 
       				$('#' + wid).window('refresh', url + '?itemId=' + row.itemId+'&ptypename='+encodeURI(ptypename));
       			}else
       			{
       				$('#' + wid).window('refresh', url + '?typeId=' + row.typeId);
       			}
       			
       		} else {
       			$.messager.alert('警告', '请选择要修改的记录！');
       		}
       	}
        
        function showItemWin(wid,url) {
        	var row = $('#typedg').datagrid('getSelected');
        	if(row!=null)
        	{
        		var ptypecode=$("#ptypeCode").val();       				
				var ptypename=$("#ptypename").val(); 
				$('#' + wid).window('refresh', url + '?&ptypename='+encodeURI(ptypename)+'&ptypeCode='+ptypecode);
        	$('#'+wid).window('open');
        	}
        	 else {
        			$.messager.alert('警告', '请先选择字典类型！');
        		}
		
        }
		
        function SearchItem() {
			$('#dg').datagrid({
				queryParams : $('#ssforms').serializeObject()
			});
		}
		
        
      //格式化状态
        function formatState(val, row) {
        	if (val == 0) {//是否启用。0表示禁用，1表示启用。
        		return "禁用";
        	}else if(val == 1){
        		return "启用";
        	} 
        }
	</script>
</body>